package com.company.strs;

import java.util.Stack;

public class BrowserHistory {

    private Stack<String> backStack = new Stack<>();
    private Stack<String> forwardStack = new Stack<>();
    private String currPage;

    public BrowserHistory(String homepage) {
        currPage = homepage;
    }

    public void visit(String url) {
        forwardStack.clear();
        backStack.push(currPage);
        currPage = url;
    }

    public String back(int steps) {
        for (int i = 0; i < steps && !backStack.isEmpty(); i++) {
            forwardStack.push(currPage);
            currPage = backStack.pop();
        }
        return currPage;
    }

    public String forward(int steps) {
        for (int i = 0; i < steps && !forwardStack.isEmpty(); i++) {
            backStack.push(currPage);
            currPage = forwardStack.pop();
        }
        return currPage;
    }
}
